//
// Created by Soar Qin on 2017/8/25.
// Copyright (c) 2017 Soar Qin. All rights reserved.
//

#include "common.hh"

#include "signal.hh"

#include "core/async/private/io_event_private.hh"

namespace core::async {

bool Signal::start(int sig) {
    if (!IoEvent::startInternal(sig, EV_PERSIST | EV_SIGNAL)) return false;
    return true;
}

void Signal::enable(bool on) {
    if (on) {
        if (event_pending(context_->ev, EV_SIGNAL, nullptr) == 0)
            event_add(context_->ev, nullptr);
    } else {
        if (event_pending(context_->ev, EV_SIGNAL, nullptr) != 0)
            event_del(context_->ev);
    }
}

void Signal::onEvent(short events) {
    onSignal();
}

}
